/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * assign3
 * Copyright (C)  Michael 2008 <mikey.morckos@gmail.com>
 * 
 * assign3 is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * assign3 is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "assign3.h"

/* INSTRUCTOR */
Img_Editor :: Img_Editor () 

: load_button("Load Image"),
  save_button("Save Image"),
  button_1_1("Apply Canny"),
  button_1_2("Apply CCLA"),

  label1("T1 :"),
  label2("T2 :"),

  frame1("CCLA"),
  frame2("Canny"),
  main_hbox(false, 5)

{
    set_border_width(10);
	set_title("Image Editor");
	
	add(main_hbox);
	
    main_hbox.set_border_width(20);
	main_hbox.pack_start(main_vbox_1);
	
	load_button.signal_clicked().connect(sigc :: mem_fun(*this, &Img_Editor :: load_Image));
    
	main_vbox_1.pack_start(load_button);
    main_vbox_1.pack_start(frame2, PACK_EXPAND_WIDGET, 20);
	main_vbox_1.pack_start(frame1, PACK_EXPAND_WIDGET, 20);
	
	/* Frame 1 */
	frame1.add(frame1_vbox_1_1);
	frame1_vbox_1_1.pack_start(button_1_2, PACK_EXPAND_WIDGET, 10);
    button_1_2.signal_clicked().connect(sigc :: mem_fun(*this, &Img_Editor :: apply_CCLA));
	/******/
	
	/* Frame 2 */
	frame2.add(frame2_vbox);
	frame2_vbox.pack_start(frame2_hbox_2_1, PACK_EXPAND_WIDGET, 5);
	frame2_vbox.pack_start(frame2_hbox_2_2, PACK_EXPAND_WIDGET, 5);
	frame2_vbox.pack_start(hbox2, PACK_EXPAND_WIDGET, 5);

    hbox2.pack_start(button_1_1, PACK_EXPAND_WIDGET, 5);
	
	frame2_hbox_2_1.pack_start(label1);
	frame2_hbox_2_1.pack_start(entry1, PACK_EXPAND_WIDGET, 5);
	
	frame2_hbox_2_2.pack_start(label2);
	frame2_hbox_2_2.pack_start(entry2, PACK_EXPAND_WIDGET, 5);

    button_1_1.signal_clicked().connect(sigc :: mem_fun(*this, &Img_Editor :: apply_Canny));
	/******/
	
	show_all_children();
}

/* DESTRUCTOR */
Img_Editor :: ~Img_Editor () {}

void Img_Editor :: load_Image () {

    cout << "Loading image..." << endl;
	
	Gtk :: FileChooserDialog dialog("Please choose an image", FILE_CHOOSER_ACTION_OPEN);
    dialog.set_transient_for(*this);

    dialog.add_button(Gtk :: Stock :: CANCEL, RESPONSE_CANCEL);
    dialog.add_button(Gtk :: Stock :: OPEN, RESPONSE_OK);

    int result = dialog.run();

    switch(result) {
        case(RESPONSE_OK) : {
            file_name = (dialog.get_filename()).c_str();
            cout << "File selected: " <<  file_name << endl;
			engine.display_Image(file_name);
            break;
        }
		case(RESPONSE_CANCEL) : break;
		default: break;
    }
	
//	engine.display_Image(0);
}

void Img_Editor :: save_Image () {

    cout << "Saving image..." << endl;
}

void Img_Editor :: apply_Canny () {

	engine.apply_Canny(atoi((entry1.get_text()).c_str()), atoi((entry2.get_text()).c_str()));
}

void Img_Editor :: apply_CCLA () {

	engine.apply_CCLA();
}

/* MAIN */
int main (int argc, char *argv[]) {

    Gtk::Main kit(argc, argv);	

    Img_Editor editor;
    Gtk::Main::run(editor);

    return 0;
}

